<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .div1 {
      width: 200px;
      height: 200px;
      border: 1px solid red;
      border-radius: 5px;
    }
    .disable {
      cursor: not-allowed;
    }
  </style>
</head>
<body>
  <h1>分页</h1>
  <div id="app">
    <div class="div1">当前是第{{currentPage}}页</div>
    <button :class="{disable: currentPage == 1}" @click="change(0)">上一页</button>
    <button v-for="num in 5" @click="change(num)">{{num}}</button>
    <button :class="{disable: currentPage == 5}" @click="change(6)">下一页</button>
  </div> 
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        // 当前的页码，默认是1
        currentPage: 1
      },
      methods: {
        // 修改页码
        change(num) {
          // 点击上一页，且页码大于1
          if(!num) {
            if(this.currentPage>1) {
              this.currentPage --
            }
          }
          // 点击下一页，且页码小于5
          else if(num === 6) {
            if(this.currentPage<5) {
              this.currentPage ++
            }
          }else {
            // 点击页码修改
            this.currentPage = num
          }
        }
      },
    })
  </script>
</body>
</html>